// app/model/friends.js
"use strict";
module.exports = (app) => {
    const crypto = require('crypto');
    const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
    // 配置（重要：一定要配置详细，一定要！！！）
    const User = app.model.define("user", {
        id: {
            type: INTEGER(20),
            primaryKey: true,
            autoIncrement: true,
        },
        username: {
            type: STRING(30),
            allowNull: false,
            defaultValue: "",
            comment: "用户名",
            unique: true,
        },
        password: {
            type: STRING,
            allowNull: false,
            defaultValue: "",
            comment: "密码",
            set(val) {
                const hmac = crypto.createHash("sha256", app.config.crypto.secret);
                hmac.update(val);
                let hash = hmac.digest("hex");
                this.setDataValue("password", hash)
            }
        },

        coin: {
            type: INTEGER,
            allowNull: false,
            defaultValue: 0,
            comment: "金币",
        },

        avatar: {
            type: STRING,
            defaultValue: "",
            comment: "头像",
        },
        name: {
            type: STRING,
            defaultValue: "",
            comment: "名称",
        },
    

        created_time: DATE,
        updated_time: DATE,

    });

    return User;
};